package HomeWork;
/*4. 十三、分别用Comparable和Comparator两个接口对下列四位同学的成绩做降序排序，
        如果成绩一样，那在成绩排序的基础上按照年龄由小到大排序。
        姓名（String）	年龄（int）	分数（double）
        liusan	          20	92.2
        lisi		      22	91.8
        wangwu		      20	99.0
        sunliu		      22	100.0*/

import java.util.Comparator;
import java.util.TreeSet;

public class test4 {
    public static void main(String[] args) {
        TreeSet<student> set = new TreeSet<>(new Comparator<student>() {
            @Override
            public int compare(student o1, student o2) {
                Double o3 = o1.getFenshu();
                Double o4 = o2.getFenshu();
                int i = o3.compareTo(o4);
                 i = i == 0 ? o1.getAge() - o2.getAge() : i;
                return i;
            }
        });

        student s1 = new student("liusan", 20, 92.2);
        student s2 = new student("lisi", 22, 91.8);
        student s3 = new student("wangwu", 20, 99.0);
        student s4 = new student("sunliu", 22, 100.0);
        set.add(s1);
        set.add(s2);
        set.add(s3);
        set.add(s4);
        for (student student : set) {
            System.out.println(student);
        }
    }
}

class student {
    private String name;
    private int age;
    private double fenshu;

    public student() {
    }

    public student(String name, int age, double fenshu) {
        this.name = name;
        this.age = age;
        this.fenshu = fenshu;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public double getFenshu() {
        return fenshu;
    }

    public void setFenshu(double fenshu) {
        this.fenshu = fenshu;
    }

    @Override
    public String toString() {
        return "student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", fenshu=" + fenshu +
                '}';
    }
}
